package com.example.imgrecognition.Activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.hardware.Camera;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.beardedhen.androidbootstrap.BootstrapButton;
import com.example.imgrecognition.MyApplication;
import com.example.imgrecognition.R;
import com.example.imgrecognition.Util.MyVideoView;
import com.example.imgrecognition.Util.ToastUtil;
import com.zk.code.net.NetUtil;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class TakeVideoActivity extends Activity {
    @BindView(R.id.normalroomVideo)
    Button normalroomVideo;
    @BindView(R.id.video)
    MyVideoView video;
    String videopath;
    public static final int RECORD_SYSTEM_VIDEO = 100;
    private static int CAMERA_ID;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_take_video);
        ButterKnife.bind(this);
        MyApplication.getInstance().addActivity(this);
        int channle =  getIntent().getIntExtra("channle",0);
        if(channle == 0){
            CAMERA_ID = 0;
        }else if(channle == 1){
            CAMERA_ID = 1;
        }else{
            CAMERA_ID = 0;
        }
        Intent i = new Intent(TakeVideoActivity.this,VideoActivity.class);
        i.putExtra("CAMERA_ID",CAMERA_ID);
        startActivityForResult(i,RECORD_SYSTEM_VIDEO);

    }
    @OnClick(R.id.normalroomVideo)
    public void onvideoClick(){

                startActivityForResult(new Intent(TakeVideoActivity.this,VideoActivity.class),RECORD_SYSTEM_VIDEO);

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data){
        super.onActivityResult(requestCode, resultCode, data);
        MyApplication.getInstance().exit();
        Intent intent = new Intent(TakeVideoActivity.this,TakePhotoActivity.class);
        startActivity(intent);
        /*if (resultCode == 2) {
            if(requestCode==RECORD_SYSTEM_VIDEO){
                if (data == null) {
                    ToastUtil.show(TakeVideoActivity.this, "未获取视频数据");
                    return;
                }
                videopath = data.getStringExtra("path");
                Uri uri = Uri.parse(videopath);
                // ToastUtil.show(AddNormalRoomActivity.this, videopath);
                MediaController c = new MediaController(this);
                c.setVisibility(View.VISIBLE);
                video.setMediaController(c);
                video.setVideoURI(uri);
                video.start();
                video.requestFocus();
                finish();
            }
        }*/
    }
}
